<template>
  <div class="app-container">
    <el-table v-if="total>0" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">

      <el-table-column align="center" label="序号" width="80">
        <template slot-scope="scope">
          <span>{{ scope.$index+(listQuery.page-1)*10+1 }}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="300px" label="标题">
        <template slot-scope="{row}">
          <router-link :to="'/operation/look/'+row.articleId" class="link-type">
            <span>{{ row.title }}</span>
          </router-link>
        </template>
      </el-table-column>

      <el-table-column width="180px" align="center" label="发布时间">
        <template slot-scope="scope">
          <span>{{ scope.row.blogTime }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column width="180px" align="center" label="观看数">
        <template slot-scope="scope">
          <span>{{ scope.row.view }}</span>
        </template>
      </el-table-column>

      <el-table-column width="180px" align="center" label="评论数">
        <template slot-scope="scope">
          <span>{{ scope.row.commentCount }}</span>
        </template>
      </el-table-column>-->
    </el-table>
    <el-table v-else />
    <pagination v-show="total>10" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

  </div>
</template>

<script>
import { fetchList } from '@/api/article'
import Pagination from '@/components/Pagination'
export default {
  name: 'MyArticleList',
  components: { Pagination },
  props: {
    userId: {
      type: String
    }
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10
      }
    }
  },
  created() {
    const userId = this.$route.params && this.$route.params.id
    if (userId !== undefined) { this.getList(userId) } else {
      const id = this.$store.state.user.id
      this.getList(id)
    }
  },
  methods: {
    getList(id) {
      fetchList(id, this.listQuery.page, this.listQuery.limit).then(response => {
        const { data } = response
        this.total = data.blogCount
        if (this.total > 0) {
          this.list = data.userBlog
        }
        this.listLoading = false
      })
        .catch(error => {
          console.log(error)
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.user-activity {
  .user-block {

    .username,
    .description {
      display: block;
      margin-left: 50px;
      padding: 2px 0;
    }

    .username{
      font-size: 16px;
      color: #000;
    }

    :after {
      clear: both;
    }

    .img-circle {
      border-radius: 50%;
      width: 40px;
      height: 40px;
      float: left;
    }

    span {
      font-weight: 500;
      font-size: 12px;
    }
  }

  .post {
    font-size: 14px;
    border-bottom: 1px solid #d2d6de;
    margin-bottom: 15px;
    padding-bottom: 15px;
    color: #666;

    .image {
      width: 100%;
      height: 100%;

    }

    .user-images {
      padding-top: 20px;
    }
  }

  .list-inline {
    padding-left: 0;
    margin-left: -5px;
    list-style: none;

    li {
      display: inline-block;
      padding-right: 5px;
      padding-left: 5px;
      font-size: 13px;
    }

    .link-black {

      &:hover,
      &:focus {
        color: #999;
      }
    }
  }

}

.box-center {
  margin: 0 auto;
  display: table;
}

.text-muted {
  color: #777;
}
</style>
